package action;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import mgr.DBMgr;

public class BoardDeleteAction implements BoardAction {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) {
		String board_num = request.getParameter("num");
		DBMgr mgr = new DBMgr();
		HttpSession session = request.getSession();
		String id = (String)session.getAttribute("id");
		String name = mgr.getName(board_num);
		String page = null;
		if(id.equals(name)){
			DBMgr mgr1 = new DBMgr();
			mgr1.delete(board_num);
			page = "http://localhost/MVCBoard/list.bo";
		}else{
			page = "http://localhost/MVCBoard/board/deleteErr.jsp";
		}//if~else
		
		try {
			response.sendRedirect(page);
		} catch (IOException e) {
			e.printStackTrace();
		}//try~catch
	}//exe
}//class
